package cn.zbmao.web.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间处理工具类
 */
public class DateUtil {
    /**
     * 获取当前时间以Date形式返回
     * @return
     */
	public static Date getNowToDate(){
		return new Date();
	}

    /**
     * 获取当前时间以int形式返回
     * @return
     */
	public static int getNowToInt(){
		return (int)(getNowToDate().getTime()/1000);
	}
	public static int getNowToIntDate(){
		
		return getTodayToInt();
	}
	
	public static int getTodayToInt(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
		String time = sdf.format(new Date());
		Date date = null;
		try {
			 date= sdf.parse(time);
		} catch (ParseException e) {
//			e.printStackTrace();
		}
		return (int)(date.getTime()/1000);
	}
	public static String getDateToStr(Date date){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = sdf.format(date);
		return time;
	}
	public static int getDateToInt(Date date){
		return (int)(date.getTime()/1000);
	}
	public static int getStringToInt(String pattern,String date){
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		Date d; 
		try {
			d= sdf.parse(date);
		} catch (ParseException e) {
			throw new RuntimeException("DateUtil.getStringToInt() has a error.");
		}
		return (int)(d.getTime()/1000);
	}
	
	public static String getDateToStr(String pattern,Date date){
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.format(date);
	}
	
	
}
